package com.smart.workflow.engine;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.espertech.esper.client.Configuration;
import com.espertech.esper.client.EPServiceProvider;
import com.espertech.esper.client.EPServiceProviderManager;
import com.espertech.esper.client.EPStatement;

/**
 * Main class that instantiates all objects required for workflow to initialize
 * event processing
 * 
 * @author Lukasz
 * 
 */
@Service("eventEngine")
public class EventEngine {
	@Resource(name = "esperConfiguration")
	private Configuration configuration;

	public EventEngine() {

	}

	public void addSubscriber(Object subscriberObject, Class eventClass) {
		configuration.addEventType(eventClass.getSimpleName(), eventClass);
		EPServiceProvider epService = EPServiceProviderManager
				.getDefaultProvider(configuration);
		EPStatement stmt = epService.getEPAdministrator().createEPL(
				"select * from " + eventClass.getSimpleName());
		stmt.setSubscriber(subscriberObject);
	}

}
